<?php

namespace App\Http\Controllers\OpenShop\Message;

use App\Http\Controllers\BaseController;
use App\Service\OpenShop\Feishu\Board\BoardParam;
use App\Service\OpenShop\Feishu\Board\BoardService;
use App\Service\OpenShop\Feishu\MessageService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class MessageController extends BaseController
{
    /**
     * 飞书任务推送的跳板url
     * @param Request $request
     */
    public function missionInfoBoard(Request $request, int $missionId)
    {
        $url = MessageService::sendBoard($request, $missionId);

        Log::info("missionInfoBoard missionId: {$missionId} url: {$url}");

        return redirect($url);
    }

    /**
     * 飞书推送专用跳板url
     * @param Request $request
     */
    public function boardUrl(Request $request)
    {
        $orderNo   = (string)$request->get('orderNo');
        $missionId = (int)$request->get('missionId');
        $boardType = (int)$request->get('boardType');

        // 跳转的curl，web/小程序
        $boardParam = (new BoardParam())
            ->setAgent($request)
            ->setOrderNo($orderNo)
            ->setMissionId($missionId);

        $url = (new BoardService($boardType, $boardParam))->getUrl();

        return redirect($url);
    }
}
